
#include "userhighlighter.h"

userhighlighter::userhighlighter(QTextDocument *parent)
    : QSyntaxHighlighter(parent)
{
    highlighted = false;

    //Quickly set up a few test highlighting colours for testing)
    QTextCharFormat newUserFormat;
    newUserFormat.setForeground(Qt::black);
    newUserFormat.setBackground(Qt::yellow);
    userFormats.push_back(newUserFormat);

    newUserFormat.setBackground(Qt::green);
    userFormats.push_back(newUserFormat);

    newUserFormat.setBackground(Qt::cyan);
    userFormats.push_back(newUserFormat);
}

void userhighlighter::highlightBlock(const QString &text) {

    if (highlighted) {
     // int offset = currentBlock().position();
        int length = currentBlock().length();

        //just highlights 3rds at the moment - need to decide on actual algorithm with team
        setFormat(0, length/3, userFormats.at(0));
        setFormat(length/3, 2*length/3, userFormats.at(1));
        setFormat(2*length/3, length, userFormats.at(2));
    }
}

void userhighlighter::toggleHighlighting(const bool mode){
    highlighted = mode;
    rehighlight();
}
